package com.example.temp.mapper;

import com.example.temp.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    // 添加用户（注册）
    @Insert("INSERT INTO USER(id, password, role) values (#{id}, #{password}, #{role})")
    int insert(User user);

    // 查询用户
    @Select("select * from USER where id = #{id} and password = #{password}")
    User find(User user);

    // 查找用户
    @Select("SELECT * FROM USER WHERE id = #{id}")
    User query(String id);

    // 修改用户信息
    @Update("update USER set password = #{password}, role = #{role} where id = #{id}")
    int update(User user);

    // 删除用户
    @Delete("DELETE FROM USER where id = #{id}")
    int delete(@Param("id") String id);
    
    // 根据角色查询用户
    @Select("SELECT * FROM USER WHERE role = #{role}")
    List<User> findByRole(@Param("role") Integer role);
    
    // 查询所有用户
    @Select("SELECT * FROM USER")
    List<User> findAll();
}
